<template>
  <van-datetime-picker
    v-model="currentDate"
    type="date"
    title="选择年月日"
    :min-date="minDate"
    :max-date="maxDate"
     @confirm="submit"
    @cancel="$emit('close')"
  />
</template>
<script>
import dayjs from 'dayjs'
import { editUserProfile } from '@/api/user'
export default {
  name:'UpdateBirthday',
  props:{
    // 接收生日
    birthday:{
      type:String
    }
  },
  data() {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(2100, 10, 1),
      currentDate: new Date(this.birthday)
    }
  },
  methods: {
    async submit() {
      // value 选中的文字，  index是对应文字所在的索引
      try {
        let birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
        await editUserProfile({
          birthday
        })
        this.$emit('update:birthday',birthday)
        this.$emit('close')
      } catch (error) {
        return this.$toast.fail('修改失败')
      }
    }
  },
}
</script>

<style>

</style>